feat: allow per-block-type content padding via DefaultTextBlockStyle - #2760
Open
Tseshongfeeshur wants to merge 1 commit into
Open
feat: allow per-block-type content padding via DefaultTextBlockStyle#2760Tseshongfeeshur wants to merge 1 commit into
Tseshongfeeshur wants to merge 1 commit into
Conversation
Currently only a single global contentPadding can be set for all text blocks, so there's no way to insert spacing between a block's content and its own decoration boundary (e.g. the left border on blockquote, the background on code block) without affecting every other block type. Add an optional `contentPadding` field to `DefaultTextBlockStyle` (and forward it through `DefaultListBlockStyle`). When set for a given block type, `EditableTextBlock` now resolves and uses it in place of the editor's global contentPadding for that block only; falls back to the previous behavior when left unset. No breaking changes: the new field is optional and defaults to null, existing DefaultTextBlockStyle constructors and copyWith calls are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DefaultTextBlockStylecurrently has no way to control the spacingbetween a block's content and its own
decoration(e.g. the leftborder on a blockquote, the background box on a code block). The
only related padding is
EditableTextBlock.contentPadding, which isa single global value shared by every block type in the editor —
there's no per-block override.
As a result, something as simple as "add a bit of vertical breathing
room between the blockquote text and its left border" isn't possible
without reaching into
text_block.dartand hardcoding values.Change
EdgeInsets? contentPaddingfield toDefaultTextBlockStyle, with the correspondingcopyWithsupport.DefaultListBlockStyle's constructor andcopyWithoverride, so list styles can opt in as well.EditableTextBlock, add_getContentPaddingForBlock()(mirrorsthe existing
_getDecorationForBlock()) to resolve a per-blockcontentPaddingfromDefaultStyles.quote/DefaultStyles.code,falling back to the editor's existing global
contentPaddingwhenthe block style doesn't define one.
Why this shape
This reuses the existing
contentPadding→RenderEditableTextBlockrendering path (which already separates decoration painting from
content padding) rather than introducing a new spacing concept, so
the actual rendering logic (
_paintDecoration,_EditableBlock,RenderEditableTextBlock) doesn't need to change at all.Compatibility
Fully backward compatible: the new field defaults to
null, andEditableTextBlockonly uses it when a block style explicitly setsit — otherwise the previous global
contentPaddingvalue is usedexactly as before. No existing call sites need to change.
Example
Testing
contentPaddingis left unset.contentPaddingonDefaultStyles.quoteaddsvertical spacing between the text and the left border without
shifting the border itself.